package com.book.dutychain;

import com.book.pojo.BusinessLaunch;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: TODO
 * @date 2024/4/9 21:40
 */
public class ProductHandler extends AbstractBuinessHandler {
    @Override
    public List<BusinessLaunch> doHandler(List<BusinessLaunch> businessLaunchList, String... args) {
        if (businessLaunchList.isEmpty() || args == null) {
            return businessLaunchList;
        }
        // 按照产品进行筛选
        businessLaunchList = businessLaunchList.stream().filter(businessLaunch -> {
            String product = businessLaunch.getTargetProduct();
            if (!StringUtils.hasLength(product)) {
                return true;
            }
            List<String> list = Arrays.asList(product.split(","));
            return list.contains(args[2]);
        }).collect(Collectors.toList());

        // 判断是否有下一个处理器
        if (hasNextHandler()) {

            return nextHandler.doHandler(businessLaunchList, args);
        }

        return businessLaunchList;
    }
}
